package com.yiren.manager.service.impl.elder;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiren.core.exception.MyException;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.FavoriteSet;
import com.yiren.core.utils.Favorites;
import com.yiren.entity.YrBeHospitalFee;
import com.yiren.entity.YrBeHospitalPledge;
import com.yiren.entity.YrElderBeHospital;
import com.yiren.entity.YrElderPayRecord;
import com.yiren.entity.YrElderWallet;
import com.yiren.entity.YrElderWalletRechargeRecord;
import com.yiren.entity.YrMealCard;
import com.yiren.entity.YrMealCardRechargeRecord;
import com.yiren.entity.YrPaper;
import com.yiren.entity.YrPaperRecord;
import com.yiren.entity.YrUserVipCard;
import com.yiren.manager.repository.cost.YrElderPayRecordRepository;
import com.yiren.manager.repository.cost.YrElderWalletRechargeRecordRepository;
import com.yiren.manager.repository.cost.YrMealCardRechargeRecordRepository;
import com.yiren.manager.repository.cost.YrPaperRecordRepository;
import com.yiren.manager.repository.cost.YrPaperRepository;
import com.yiren.manager.repository.elder.YrBeHospitalFeeRepository;
import com.yiren.manager.repository.elder.YrElderBeHospitalRepository;
import com.yiren.manager.repository.elder.YrElderWalletRepository;
import com.yiren.manager.repository.lease.YrBeHospitalPledgeRepository;
import com.yiren.manager.repository.messhall.YrMealCardRepositoty;
import com.yiren.manager.repository.vip.YrUserVipCardRepository;
import com.yiren.manager.service.iface.elder.YrBeHospitalFeeService;

@Service
public class YrBeHospitalFeeServiceImpl extends GenericServiceImpl<YrBeHospitalFee, String> implements YrBeHospitalFeeService{
	
	@Autowired
	private YrElderWalletRepository elderWalletRepository;
	
	@Autowired
	private YrMealCardRepositoty mealCardRepositoty;
	
	@Autowired
	private YrBeHospitalPledgeRepository beHospitalPledgeRepository;
	
	@Autowired
	private YrElderBeHospitalRepository elderBeHospitalRepository;
	
	@Autowired
	private YrElderPayRecordRepository elderPayRecordRepository;
	
	@Autowired
	private YrElderWalletRechargeRecordRepository elderWalletRechargeRecordRepository;
	
	@Autowired
	private YrMealCardRechargeRecordRepository mealCardRechargeRecordRepository;
	
	@Autowired
	private YrUserVipCardRepository userVipCardRepository;
	
	@Autowired
	private YrPaperRecordRepository paperRecordRepository;
	
	@Autowired
	private YrPaperRepository paperRepository;
	
	@Autowired
	public YrBeHospitalFeeServiceImpl(YrBeHospitalFeeRepository repository) {
		super(repository);
	}
	
	@Override
	public void addByFavoriteSet(FavoriteSet entitys) throws MyException {
		YrBeHospitalFee beHospitalFee = entitys.getFavorite("beHospitalFee",YrBeHospitalFee.class);
		YrElderWallet elderWallet = entitys.getFavorite("elderWallet",YrElderWallet.class);
		YrMealCard mealCard = entitys.getFavorite("mealCard",YrMealCard.class);
		YrBeHospitalPledge hospitalPledge = entitys.getFavorite("beHospitalPledge",YrBeHospitalPledge.class);
		
		YrElderBeHospital elderBeHospital = entitys.getFavorite("elderBeHospital",YrElderBeHospital.class);
		List<YrElderPayRecord> elderPayRecords = entitys.getFavorite("elderPayRecords",List.class);
		YrMealCardRechargeRecord mealCardRechargeRecord = entitys.getFavorite("mealCardRechargeRecord",YrMealCardRechargeRecord.class);
		YrElderWalletRechargeRecord elderWalletRechargeRecord = entitys.getFavorite("elderWalletRechargeRecord",YrElderWalletRechargeRecord.class);
		YrUserVipCard userVipCard = entitys.getFavorite("userVipCard",YrUserVipCard.class);
		
		YrPaperRecord pledePaperRecord = entitys.getFavorite("pledePaperRecord", YrPaperRecord.class);
		YrPaperRecord payPaperRecord = entitys.getFavorite("payPaperRecord", YrPaperRecord.class);
		YrPaper paper = entitys.getFavorite("paper", YrPaper.class);
		
		this.repository.save(beHospitalFee);
		elderWalletRepository.save(elderWallet);
		mealCardRepositoty.save(mealCard);
		beHospitalPledgeRepository.save(hospitalPledge);
		
		elderBeHospitalRepository.save(elderBeHospital);
		if(null!=userVipCard){
			userVipCardRepository.save(userVipCard);
		}
		for(YrElderPayRecord elderPayRecord : elderPayRecords){
			elderPayRecordRepository.save(elderPayRecord);
		}
		if(null!=mealCardRechargeRecord){
			mealCardRechargeRecordRepository.save(mealCardRechargeRecord);
		}
		if(null!=elderWalletRechargeRecord){
			elderWalletRechargeRecordRepository.save(elderWalletRechargeRecord);
		}
		if(null!=pledePaperRecord){
			paperRecordRepository.save(pledePaperRecord);
		}
		if(null!=payPaperRecord){
			paperRecordRepository.save(payPaperRecord);
		}
		paperRepository.save(paper);
	}
	
	public void modifyByFavorites(Favorites entitys) throws MyException {
		// TODO Auto-generated method stub
		
	}



}
